<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>flex实现水平垂直居中</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,body {
            width: 100%;
            height: 100%;
        }

        .container {
            width: 100%;
            height: 100%;
            display: flex;
            /* 水平居中 */
            justify-content: center;
            /* 垂直居中 */
            align-items: center;
        }

        .center {
            width: 200px;
            height: 200px;
            background-color: lightpink;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="center"></div>
    </div>
</body>

</html>